#!/bin/bash

# 启动脚本

APP_NAME="data-sync-task"
JAR_NAME="data-sync-task-1.0.0.jar"
LOG_FILE="logs/app.log"

# 检查是否已经运行
PID=$(ps -ef | grep ${JAR_NAME} | grep -v grep | awk '{print $2}')
if [ -n "$PID" ]; then
    echo "❌ 应用已经在运行中，PID: $PID"
    exit 1
fi

# 启动应用
echo "=========================================="
echo "启动 ${APP_NAME}..."
echo "=========================================="

nohup java -jar \
    -Xms512m \
    -Xmx1024m \
    -Dspring.config.location=config/application.yml \
    ${JAR_NAME} \
    > ${LOG_FILE} 2>&1 &

# 等待启动
sleep 3

# 检查是否启动成功
PID=$(ps -ef | grep ${JAR_NAME} | grep -v grep | awk '{print $2}')
if [ -n "$PID" ]; then
    echo "✅ 启动成功！PID: $PID"
    echo "日志文件: ${LOG_FILE}"
    echo "查看日志: tail -f ${LOG_FILE}"
else
    echo "❌ 启动失败！请查看日志文件"
    exit 1
fi

echo "=========================================="
